package NIOCommunication;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;

public class Connection
{
	private SocketChannel mSocketChannel = null;
	
	public Connection(SocketChannel socketChannel)
	{
		mSocketChannel = socketChannel;
	}
	
	public Connection(String host, int port) throws IOException
	{
		InetSocketAddress isa = new InetSocketAddress(InetAddress.getByName(host), port);
		mSocketChannel = SocketChannel.open();
		mSocketChannel.connect(isa);
	}
	
	public void Close() throws IOException
	{
		if(mSocketChannel != null)
		{
			mSocketChannel.close();
			mSocketChannel = null;
		}
	}
}
